C                                                           DEWIT
C
C  Dewhitens an input sequence in-place.  Uses a low-order prediction 
C    filter from prewit.
C
C  Author:  George Randall from prewit by Dave Harris
C
C  Created:  February 10, 1987
C
C  Last Modified:  February 10, 1987
C
C  Input arguments:
C  ----- ----------
C
C    DATA                 REAL*4 array containing input sequence - contains
C                         dewhitened sequence upon exit from this routine.
C
C    #SAMPLES             Number of data points in sequence.
C
C    PREDICTOR_ORDER      Order of prediction filter used to dewhiten
C                         sequence.
C
C  Output Arguments:
C  ------ ----------
C
C    DATA                 As above.
C
C    A                    Array of dewhitening filter coefficients.
C
C    ERROR_MESSAGE        CHARACTER*130 variable containing error message if
C                         error is detected.  Equal to ' ' if no errors.
C
C  Linkage:     PREDFL
C
C
      subroutine dewit(data, nsamps, order, a, errmsg)
C
        real*4 data(1), a(1), atemp(13)
        character*130 errmsg
        integer order, nsamps
C
C  Initializations
C
        errmsg = ' '
C
C  Range check for predictor order
C
        if (  order .lt. 1 .or. order .gt. 12 ) then
          errmsg = '*** DEWIT  -  Predictor order out of bounds (1-12)
     1***'
        end if
C
C  Dewhiten the data
C
C    Negate coefficients of prediction error filter generated by LEVIN.
C    For historical reasons, different storage modes are used in LEVIN
C    and PEF and PREDFL.
C
        do    1 i = 1, order
          atemp(i) = -a(i+1)
C             I
    1   continue
C
        call predfl(data, nsamps, atemp, order, data, errmsg)
        if (.not.( errmsg .eq. ' ' )) then
          call append(errmsg, '$ from (DEWIT)$')
        end if
C
      return
      end
